package com.small.site.util;

import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;

/**
 * @author xiaochi
 * @date 2021/12/2 17:18
 * @desc ToolUtil 工具类
 */
public class ToolUtil {

    /**
     * length用户要求产生字符串的长度
     * @param length
     * @return
     */
    public String getRandomString(int length){
        String str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        Random random = ThreadLocalRandom.current();
        StringBuilder sb=new StringBuilder();
        for(int i=0;i<length;i++){
            int number=random.nextInt(62);
            sb.append(str.charAt(number));
        }
        return sb.toString();
    }
}
